from datetime import datetime

import peewee
import peewee_async
from peewee import *

db = peewee.MySQLDatabase("messages", host="127.0.0.1", port=3306, user="root", password="")

database = peewee_async.MySQLDatabase(database="messages", host="127.0.0.1", port=3306, user="root", password="")
database.set_allow_sync(False)

objects = peewee_async.Manager(database)


class Message(Model):
    name = CharField(max_length=10, verbose_name="姓名")
    email = CharField(max_length=32, verbose_name="邮箱")
    address = CharField(max_length=64, verbose_name="地址")
    message = TextField(verbose_name="留言")
    create_time = DateTimeField(default=datetime.now, verbose_name="创建时间")
    update_time = DateTimeField(default=datetime.now, verbose_name="更新时间")

    class Meta:
        database = db  # 指定连接的数据库
        table_name = "messages"  # 指定表名


if __name__ == '__main__':
    db.create_tables([Message])